home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / winlib.lzh / WINLIB / XAES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  9.6 KB  |  383 lines

  1. /********************************************************************
  2.  *                                                                    *
  3.  *    WinLIB PRO Revision II: Extended AES segment                    *
  4.  *                                                                    *
  5.  *    Copyright (C) 1994, Bitgate Software                            *
  6.  *                                                                    *
  7.  ********************************************************************/
  8.  
  9. #include <stddef.h>
  10. #include <string.h>
  11. #include "winlib.h"
  12.  
  13. #ifndef __XAES__
  14. #define __XAES__
  15. #endif
  16.  
  17. /* Fixed linepattern stuff by putting the animation in an
  18.    array instead. This is really pretty stupid, since a simple
  19.    680x0 ROL instruction would rotate the pattern as we wanted
  20.    to. C kinda sucks sometimes. -KA */
  21. int linepatterns[] = {0x7FF8, 0x3FFC, 0x1FFE, 0x0FFF, 0x87FF, 0xC3FF, 0xE1FF, 0xF0FF,
  22.                       0xF87F, 0xFC3F, 0xFE1F, 0xFF0F, 0xFF87, 0xFFC3, 0xFFE1, 0xFFF0};
  23.  
  24. /*
  25.  *    Drag or move a custom designed box
  26.  *    Written by Ken Hollis
  27.  *
  28.  *    width, height, beginx, beginy = beginning rectangle coordinates
  29.  *    boundx, boundy, boundw, boundh = rectangle boundaries
  30.  *    linecolor = color of line to draw
  31.  *    linetype = type of line to draw
  32.  *    linepattern = pattern of line if custom line
  33.  *    *endx, *endy = ending coordinates (x, y) of box
  34.  *    animate = flag for internal line drawing animation
  35.  *
  36.  *    Boundaries can be switched on or off at will.  For instance, if
  37.  *    the programmer doesn't want an X boundary, it is defined as -1,
  38.  *    the Y boundary is the same, and so are all other variables,
  39.  *    respectively.  Only those ENABLED variables are the ones that
  40.  *    are used.
  41.  *
  42.  *    It's a bit messy, but everything's commented, so there should be
  43.  *    no problems.
  44.  */
  45. GLOBAL void WDragBox(int width, int height, int beginx, int beginy,
  46.             int boundx, int boundy, int boundw, int boundh,
  47.             int linecolor, int linetype, int linepattern,
  48.             int *endx, int *endy, int animate)
  49. {
  50.     int mx = 0, my = 0, button, dummy, origx, origy, cntr = 0, xo,
  51.         yo, dx = 0, dy = 0;
  52.     int attributes[6], modeattributes[10], pxy[20], fillattributes[5];
  53.     int linepat = 0;
  54.     GRECT pos;
  55.  
  56.     /* Clear out the ending values for now */
  57.     *endx = 0;
  58.     *endy = 0;
  59.  
  60.     /* Get line and graphics mode attributes */
  61.     vql_attributes(VDIhandle, attributes);
  62.     vqt_attributes(VDIhandle, modeattributes);
  63.     vqf_attributes(VDIhandle, fillattributes);
  64.  
  65.     /* Get the original position of the mouse at startup */
  66.     graf_mkstate(&origx, &origy, &dummy, &dummy);
  67.  
  68.     /* Remove clipping for now (yes, this HAS to be done!) */
  69.     pxy[0] = desk.g_x;
  70.     pxy[1] = desk.g_y;
  71.     pxy[2] = desk.g_x + desk.g_w;
  72.     pxy[3] = desk.g_y + desk.g_h;
  73.  
  74.     vs_clip(VDIhandle, 1, pxy);
  75.  
  76.     /* Set attributes */
  77.     vsl_color(VDIhandle, linecolor);
  78.     if (animate) {
  79.         vsl_type(VDIhandle, USERLINE);
  80.         vsl_udsty(VDIhandle, linepatterns[linepat]);
  81.     } else
  82.         if (linetype == USERLINE) {
  83.             vsl_type(VDIhandle, USERLINE);
  84.             vsl_udsty(VDIhandle, linepattern);
  85.         } else
  86.             vsl_type(VDIhandle, linetype);
  87.         
  88.     vswr_mode(VDIhandle, MD_XOR);
  89.  
  90.     pos.g_x = beginx;
  91.     pos.g_y = beginy;
  92.     pos.g_w = width;
  93.     pos.g_h = height;
  94.  
  95.     WGrafMouse(M_OFF);
  96.  
  97.     pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  98.     pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  99.     pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  100.     pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  101.     v_pline(VDIhandle, 5, pxy);
  102.  
  103.     WGrafMouse(M_ON);
  104.  
  105.     do {
  106.         /* Store the mouse positions */
  107.         xo = mx;
  108.         yo = my;
  109.  
  110.         /* Get mouse coordinates and button state */
  111.         graf_mkstate(&mx, &my, &button, &dummy);
  112.  
  113.         /* Calculate the mouse movement difference */
  114.         dx = mx - xo;
  115.         dy = my - yo;
  116.  
  117.         /* Increase the animation-pause step counter */
  118.         cntr++;
  119.  
  120.         if (!animate) {
  121.             if (dx || dy)
  122.                 WGrafMouse(M_OFF);    /* Turn off the mouse */
  123.         } else
  124.             WGrafMouse(M_OFF);
  125.  
  126.         /* Draw the original box to erase it (remember MD_XOR) */
  127.         pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  128.         pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  129.         pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  130.         pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  131.         Vsync();
  132.         v_pline(VDIhandle, 5, pxy);
  133.  
  134.         /* Let the new box equal the mouse position minus the offset
  135.            so it's positioned to where the mouse was first clicked */
  136.         pos.g_x = beginx + (mx - origx);
  137.         pos.g_y = beginy + (my - origy);
  138.  
  139.         /* Check the width boundary of the box */
  140.         if (boundw != -1) {
  141.             int tx;
  142.  
  143.             /* Find the offset from the width boundary */
  144.             if ((tx = (pos.g_x + pos.g_w) - (boundw)) < 0)
  145.                 tx = 0;
  146.             else
  147.                 tx += 1;
  148.  
  149.             /* And reposition the x offset of the drawn box */
  150.             pos.g_x -= tx;
  151.         }
  152.  
  153.         /* Check the height boundary of the box */
  154.         if (boundh != -1 && boundy != -1) {
  155.             int ty;
  156.  
  157.             /* Find the offset from the height boundary */
  158.             if ((ty = (pos.g_y + pos.g_h) - (boundy + boundh)) < 0)
  159.                 ty = 0;
  160.             else
  161.                 ty += 1;
  162.  
  163.             /* And reposition the y offset of the drawn box */
  164.             pos.g_y -= ty;
  165.         }
  166.  
  167.         /* Check the x boundary of the box */
  168.         if (boundx != -1)
  169.             if (pos.g_x < boundx)
  170.                 pos.g_x = boundx;
  171.  
  172.         /* Check the y boundary of the box */
  173.         if (boundy != -1)
  174.             if (pos.g_y < boundy)
  175.                 pos.g_y = boundy;
  176.  
  177.         /* Check animation pause counter */
  178.         if (cntr == 1) {
  179.             cntr = 0;    /* Reset the counter */
  180.  
  181.             if (animate) {
  182.                 linepat = (linepat + 1) & 0xf;
  183.                 vsl_udsty(VDIhandle, linepatterns[linepat]);
  184.             }
  185.         }
  186.  
  187.         /* Draw the new box at the new coordinates */
  188.         pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  189.         pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  190.         pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  191.         pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  192.         v_pline(VDIhandle, 5, pxy);
  193.         Vsync();
  194.  
  195.         if (!animate) {
  196.             if (dx || dy)
  197.                 WGrafMouse(M_ON);    /* Turn on the mouse */
  198.         } else WGrafMouse(M_ON);
  199.     } while (button);
  200.  
  201.     /* Turn off the mouse again */
  202.     WGrafMouse(M_OFF);
  203.  
  204.     /* Erase the box so it doesn't show anymore */
  205.     pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  206.     pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  207.     pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  208.     pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  209.     v_pline(VDIhandle, 5, pxy);
  210.  
  211.     /* And turn on the mouse */
  212.     WGrafMouse(M_ON);
  213.  
  214.     /* Reset the clipping rectangle at its original place, just in
  215.        case it happened to have been this.  Won't hurt anything. */
  216.     pxy[0] = beginx;
  217.     pxy[1] = beginy;
  218.     pxy[2] = width;
  219.     pxy[3] = height;
  220.  
  221.     vs_clip(VDIhandle, 1, pxy);
  222.  
  223.     /* Restore all drawing modes */
  224.     vsl_color(VDIhandle, attributes[1]);
  225.     vsl_type(VDIhandle, attributes[0]);
  226.     vsl_udsty(VDIhandle, 0xFFFF);
  227.     vst_color(VDIhandle, modeattributes[1]);
  228.     vswr_mode(VDIhandle, modeattributes[5]);
  229.     vsf_color(VDIhandle, fillattributes[1]);
  230.     vsf_interior(VDIhandle, fillattributes[0]);
  231.     vsf_style(VDIhandle, fillattributes[2]);
  232.  
  233.     /* and return the ending values */
  234.     *endx = pos.g_x;
  235.     *endy = pos.g_y;
  236. }
  237.  
  238. GLOBAL void WGraf_Rubberbox(int bx, int by, int linecolor, int linetype, int linepattern,
  239.             int *endx, int *endy, int animate)
  240. {
  241.     int mx, my, button, dummy, origx, origy, cntr = 0,
  242.         boundx, boundy, boundw, boundh;
  243.     int attributes[6], modeattributes[10], pxy[20], fillattributes[5];
  244.     int linepat = 0;
  245.     GRECT pos;
  246.  
  247.     *endx = 0;
  248.     *endy = 0;
  249.  
  250.     vql_attributes(VDIhandle, attributes);
  251.     vqt_attributes(VDIhandle, modeattributes);
  252.     vqf_attributes(VDIhandle, fillattributes);
  253.  
  254.     graf_mkstate(&origx, &origy, &dummy, &dummy);
  255.  
  256.     pxy[0] = desk.g_x;
  257.     pxy[1] = desk.g_y;
  258.     pxy[2] = desk.g_x + desk.g_w;
  259.     pxy[3] = desk.g_y + desk.g_h;
  260.  
  261.     vs_clip(VDIhandle, 1, pxy);
  262.  
  263.     vsl_color(VDIhandle, linecolor);
  264.     if (animate) {
  265.         vsl_type(VDIhandle, USERLINE);
  266.         vsl_udsty(VDIhandle, linepatterns[linepat]);
  267.     } else
  268.         if (linetype == USERLINE) {
  269.             vsl_type(VDIhandle, USERLINE);
  270.             vsl_udsty(VDIhandle, linepattern);
  271.         } else
  272.             vsl_type(VDIhandle, linetype);
  273.         
  274.     vswr_mode(VDIhandle, MD_XOR);
  275.  
  276.     pos.g_x = bx;
  277.     pos.g_y = by;
  278.     pos.g_w = 0;
  279.     pos.g_h = 0;
  280.  
  281.     WGrafMouse(M_OFF);
  282.  
  283.     pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  284.     pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  285.     pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  286.     pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  287.     v_pline(VDIhandle, 5, pxy);
  288.  
  289.     WGrafMouse(M_ON);
  290.  
  291.     boundx = desk.g_x;
  292.     boundy = desk.g_y;
  293.     boundw = desk.g_w;
  294.     boundh = desk.g_h;
  295.  
  296.     do {
  297.         graf_mkstate(&mx, &my, &button, &dummy);
  298.  
  299.         cntr++;
  300.  
  301.         WGrafMouse(M_OFF);
  302.  
  303.         pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  304.         pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  305.         pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  306.         pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  307.         Vsync();
  308.         v_pline(VDIhandle, 5, pxy);
  309.  
  310.         pos.g_w = mx - pos.g_x;
  311.         pos.g_h = my - pos.g_y;
  312.  
  313.         if (boundw!=-1) {
  314.             int tx;
  315.  
  316.             if ((tx = (pos.g_x + pos.g_w) - (boundw)) < 0)
  317.                 tx = 0;
  318.             else
  319.                 tx += 1;
  320.  
  321.             pos.g_x -= tx;
  322.         }
  323.  
  324.         if (boundh != -1 && boundy != -1) {
  325.             int ty;
  326.  
  327.             if ((ty = (pos.g_y + pos.g_h) - (boundy + boundh)) < 0)
  328.                 ty = 0;
  329.             else
  330.                 ty += 1;
  331.  
  332.             pos.g_y -= ty;
  333.         }
  334.  
  335.         if (boundx != -1)
  336.             if (pos.g_x < boundx)
  337.                 pos.g_x = boundx;
  338.  
  339.         if (boundy != -1)
  340.             if (pos.g_y < boundy)
  341.                 pos.g_y = boundy;
  342.  
  343.         if (cntr == 1) {
  344.             cntr = 0;    /* Reset the counter */
  345.  
  346.             if (animate) {
  347.                 linepat = (linepat + 1) & 0xf;
  348.                 vsl_udsty(VDIhandle, linepatterns[linepat]);
  349.             }
  350.         }
  351.  
  352.         pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  353.         pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  354.         pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  355.         pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  356.         v_pline(VDIhandle, 5, pxy);
  357.         Vsync();
  358.  
  359.         WGrafMouse(M_ON);
  360.     } while (button);
  361.  
  362.     WGrafMouse(M_OFF);
  363.  
  364.     pxy[0] = pxy[6] = pxy[8] = pos.g_x;
  365.     pxy[1] = pxy[3] = pxy[9] = pos.g_y;
  366.     pxy[2] = pxy[4] = pos.g_x + pos.g_w;
  367.     pxy[5] = pxy[7] = pos.g_y + pos.g_h;
  368.     v_pline(VDIhandle, 5, pxy);
  369.  
  370.     WGrafMouse(M_ON);
  371.  
  372.     vsl_color(VDIhandle, attributes[1]);
  373.     vsl_type(VDIhandle, attributes[0]);
  374.     vsl_udsty(VDIhandle, 0xFFFF);
  375.     vst_color(VDIhandle, modeattributes[1]);
  376.     vswr_mode(VDIhandle, modeattributes[5]);
  377.     vsf_color(VDIhandle, fillattributes[1]);
  378.     vsf_interior(VDIhandle, fillattributes[0]);
  379.     vsf_style(VDIhandle, fillattributes[2]);
  380.  
  381.     *endx = pos.g_x;
  382.     *endy = pos.g_y;
  383. }